<form class="layui-form seller-form"  action="" >
    <div class="layui-form-item" style="margin-bottom:0;">
        <div class="layui-inline">
            <label class="layui-form-label">退款单号：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="refund_id" lay-verify="title" placeholder="请输入退款单号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <!--<div class="layui-inline">-->
            <!--<label class="layui-form-label">单号</label>-->
            <!--<div class="layui-input-inline seller-inline-3">-->
                <!--<input type="text" name="source_id" lay-verify="title" placeholder="" autocomplete="off" class="layui-input">-->
            <!--</div>-->
        <!--</div>-->

        <div class="layui-inline">
            <label class="layui-form-label" style="width:120px;">用户手机号码：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="mobile" lay-verify="title" placeholder="请输入手机号码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态：</label>
            <div class="layui-input-inline seller-inline-2" >
                <select name="status" lay-verify="">
                    <option value=""></option>
                    <option value="1">待退款</option>
                    <option value="2">退款成功</option>
                    <option value="3">其他</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>筛选</button>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="billRefund" lay-filter="test"></table>
</div>

<script>
    layui.use(['form', 'layedit', 'laydate','table'], function(){
        layui.table.render({
            elem: '#billRefund',
            height: 'full-330',
            cellMinWidth: '80',
            page: 'true',
            limit:'20',
            url: "{:url('billRefund/index')}?_ajax=1",
            id:'billRefund',
            cols: [[
                {field:'refund_id', width:140, sort: true,title:'退款单号'},
                {field:'money',width:100,title:'退款金额'},
                {field:'payment_code', width:140, sort: true,title:'退款方式'},
                {field:'status_name', width:100,title:'状态'},
                {field:'type', width:100,title:'类型'},
                {field:'source_id', sort: true,title:'单号'},
                {field:'user_id', width:150,minWidth: 50,title:'用户'},
                {field:'ctime',width:170,title:'创建时间'},
                {field: 'operating', title: '操作', width:120, align: 'center',templet:function(data){
                    var html = '';
                    if(data.status == 1){
                        html += '<a  class="layui-btn layui-btn-xs option-audit" data-id="' + data.refund_id + '">退款</a>';
                    }
                    if(data.status == 3){
                        html += '<a  class="layui-btn layui-btn-xs option-reaudit" data-id="' + data.refund_id + '">再次退款</a>';
                    }
                    html += '<a  class="layui-btn layui-btn-xs option-view layui-btn-primary" data-id="' + data.refund_id + '">明细</a>';
                    return html;
                }},
            ]]
        });
        layui.form.on('submit(*)', function(data){
            layui.table.reload('billRefund', {
                where: data.field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //审核操作
        $(document).on('click','.option-audit',function(){
            $.ajax({
                type:'get',
                url: "{:url('billRefund/refund')}",
                data:'refund_id='+$(this).attr('data-id'),
                success:function(e){
                    if(e.status){
                        window.box = layer.open({
                            type: 1,
                            content: e.data,
                            area: ['600px', '400px'],
                            title:'退款单审核',
                            btn: ['确认','取消'],
                            yes: function(index, layero){
                                $.ajax({
                                    type:'post',
                                    url: "{:url('billRefund/refund')}",
                                    data: $('#refund_form').serialize(),
                                    success:function(res){
                                        if(res.status){
                                            layer.msg('退款成功');
                                        }else{
                                            layer.msg(res.msg);
                                        }
                                        layer.close(index);
                                        layui.table.reload('billRefund');
                                        return false;
                                    }
                                });
                            }
                        });
                    }else{
                        layer.msg(e.msg);
                    }

                }
            });
        });
        //退款失败后，再次退款
        $(document).on('click','.option-reaudit',function(){
            $.ajax({
                type:'post',
                url: "{:url('billRefund/reaudit')}",
                data: 'refund_id='+$(this).attr('data-id'),
                success:function(res){
                    if(res.status){
                        layer.msg('保存成功');
                    }else{
                        layer.msg(res.msg);
                    }
                    layui.table.reload('billRefund');;
                    return false;
                }
            });
        });
        //查看操作
        $(document).on('click','.option-view',function(){
            $.ajax({
                type:'get',
                url: "{:url('billRefund/view')}",
                data:'refund_id='+$(this).attr('data-id'),
                success:function(e){
                    if(e.status){
                        window.box = layer.open({
                            type: 1,
                            content: e.data,
                            area: ['600px', '400px'],
                            title:'退款单查看'
                        });
                    }else{
                        layer.msg(e.msg);
                    }

                }
            });
        });
    });
</script>
